﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Backend.Packets;

namespace GameClient.Managers
{
    /// <summary>
    /// Singleton mantaining all state of a connection.
    /// </summary>
    class ClientManager
    {
        private static ClientManager m_Instance = null;

        //Managers
        private AccountManager m_AccountManager;
        private ChatManager m_ChatManager;

        //Contains pointer to a method for sending data to remote host.
        public delegate void SendDelegate(IPacket Packet);
        private SendDelegate m_Sender;

        public event Action<string> ServerResponse;

        public void ServerMessage(string Message)
        {
            if (ServerResponse != null)
                ServerResponse(Message + "\r\n");
        }

        public AccountManager AccountMgr
        {
            get
            {
                return m_AccountManager;
            }
        }

        public void RegisterSend(SendDelegate Func)
        {
            m_Sender = new SendDelegate(Func);
        }

        public ChatManager ChatMgr
        {
            get
            {
                return m_ChatManager;
            }
        }

        public void Send(IPacket Packet)
        {
            if (m_Sender != null)
                m_Sender(Packet);
        }

        public static ClientManager GetInstance()
        {
            if (m_Instance == null)
                m_Instance = new ClientManager();

            return m_Instance;
        }

        private ClientManager()
        {
            m_AccountManager = new AccountManager();
            m_ChatManager = new ChatManager();
        }
    }
}
